package com.hong.spring.config;

import com.hong.spring.listener.ConsumerCommon;
import com.sproutsocial.nsq.MessageDataHandler;
import com.sproutsocial.nsq.MessageHandler;
import com.sproutsocial.nsq.Subscriber;
import lombok.extern.log4j.Log4j2;

/**
 * @author: csh
 * @Date: 2021/4/27 18:06
 * @Description:zero配置
 */
@Log4j2
public class NsqMqConsumer extends Subscriber{
    //topic
    private String topic;
    //channel
    private String channel;

    //消息费
    private ConsumerCommon  consumerCommon;

    public NsqMqConsumer(String... lookupHosts) {
        super(lookupHosts);
    }

    public void init(){
        subscribe(topic,channel,consumerCommon::handleData);
    }

    @Override
    public synchronized void subscribe(String topic, String channel, MessageDataHandler handler) {
        super.subscribe(topic, channel,  handler);
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public ConsumerCommon getConsumerCommon() {
        return consumerCommon;
    }

    public void setConsumerCommon(ConsumerCommon consumerCommon) {
        this.consumerCommon = consumerCommon;
    }
}
